<?php
e($javascript->link('jquery'));
$this->pageTitle = ucfirst($post['Post']['title']).$brand;
?>
<script>
    $(document).ready(function(){
        $('#CommentAddForm').submit(function(){
            $('.error').empty();
            $('#commentError').empty().append('Saving your comments ...').show();
            var input_name = $('#CommentName').val();
            var input_email = $('#CommentEmail').val();
            var input_website = $('#CommentWebsite').val();
            var input_description = $('#CommentDescription').val();
            var input_post = $('#CommentPost').val();
            
            if(input_name.length<1){$('#error-name').append('your name still empty');}
            if(input_email.length<1){$('#error-email').append('your email still empty');}
            if(input_description.length<1){$('#error-description').append('your comment still empty');}
            if(input_post.length<1){$('#commentError').empty().append('Something error. Please refresh your browser').show();}

            $('#CommentName').change(function(){$('#error-name').empty();});
            $('#CommentEmail').change(function(){$('#error-email').empty();});
            $('#CommentDescription').change(function(){$('#error-description').empty();});
            if(input_name.length>0 && input_email.length>0 && input_description.length>0 && input_post.length>0){
                $('#commentError').hide();
                 $.ajax({
                    type: "POST",
                    data: ({name : input_name,email: input_email,website:input_website,description:input_description,post:input_post}),
                    dataType: "json",
                    url: "<?=$baseUrl?>/comments/addComment",

                    success: function(data){
                        if(data.result){
                            if(data.result == '1'){
                                $('#CommentDescription').val('');
                                $('#logo-content-comment').append('<div class="comment-block"><div class="comment-block-image"><img height="50" width="50" src="http://www.gravatar.com/avatar/'+data.email+'?s=50&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G" alt="'+input_name+'" /></div><div class="comment-block-description"><h1><a href="'+input_website+'">'+input_name+'</a> [being moderation] says :</h1><p>'+input_description+'</p></div><div class="clear"></div></div>');
                                $('#commentError').empty().append('Thanks for your comments').show();
                            }else{
                                $('#CommentDescription').val('');
                                $('#logo-content-comment').append('<div class="comment-block"><div class="comment-block-image"><img height="50" width="50" src="http://www.gravatar.com/avatar/'+data.email+'?s=50&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G" alt="'+input_name+'" /></div><div class="comment-block-description"><h1><a href="'+input_website+'">'+input_name+'</a> says :</h1><p>'+input_description+'</p></div><div class="clear"></div></div>');
                                $('#commentError').empty().append('Thanks for your comments').show();
                            }
                        }else if(data.error){
                            if(data.error == '0'){ $('#commentError').empty().append('Forms still empty').show();}
                            else if(data.error == '1') {$('#commentError').empty().append('Something error. Please refresh your browser').show();}
                            else if(data.error == '2') {$('#commentError').empty().append('Something error. Please refresh your browser').show();}
                            else if(data.error.email == '3') {$('#error-email').empty().append('your email not valid');}
                            else if(data.error == '4') {$('#commentError').empty().append('Failed saving your comment. Please try again').show();}
                            else if(data.error == '5') {$('#commentError').empty().append('Sorry, it was an failure when receiving your comment').show();}
                            else if(data.error == '6') {$('#commentError').empty().append('Sorry, you already have same comment before').show();}
                            else {
                                $('#commentError').empty().append('Please check your connection').show();
                            }
                        }else{
                            $('#commentError').empty().append('Something trouble. Please refresh your browser').show();
                        }
                    },
                    error:function(XMLHttpRequest,textStatus, errorThrown)
                    {
                        var status = XMLHttpRequest.status;
                        if(status == '403'){
                            $('#commentError').empty().append('Please check your connection').show();
                        }
                    }
                });
            }

            return false;
        });

        $('#logo-content-favorite-box a#favorite-like').click(function(){
            $('#logo-content-favorite-result').empty().hide();
            var input_post = '<?=$post['Post']['slug']?>';
            var input_user = '<?=$_SERVER["REMOTE_ADDR"]?>';
            
            if(input_post.length>0 && input_user.length>0){
                 $.ajax({
                    type: "POST",
                    data: ({post: input_post,user:input_user}),
                    dataType: "json",
                    url: "<?=$baseUrl?>/rates/add",

                    success: function(data){
                        $('#commentError').hide();
                        if(data.result){
                            if(data.result == '1'){
                                $('#logo-content-favorite-box').remove();
                                $('#logo-content-favorite-result').append('Thanks for like it!').fadeIn('slow');
                            }else{
                                $('#logo-content-favorite-result').append('Failed. Please try again').fadeIn('slow');
                            }
                        }else if(data.error){
                            if(data.error == '0'){
                                $('#logo-content-favorite-box').remove();
                                $('#logo-content-favorite-result').append('Sorry, you have rated before.').fadeIn('slow');
                            }else{
                                $('#logo-content-favorite-box').remove();
                                $('#logo-content-favorite-result').append('Something error. Please refresh your browser.').fadeIn('slow');
                            }
                        }else{
                            $('#logo-content-favorite-result').append('Please check your connection.').fadeIn('slow');
                        }
                    },
                    error:function(XMLHttpRequest,textStatus, errorThrown)
                    {
                        var status = XMLHttpRequest.status;
                        if(status == '403'){
                            $$('#logo-content-favorite-result').append('Please check your connection.').fadeIn('slow');
                        }
                    }
                });
            }

            return false;
        });
    });
</script>
<div id="logo">
    <div id="logo-content">
        <?php if(isset($result)) :?>
            <div id="logo-keyword">You're incoming from <strong><?=$result['0']?></strong> with keyword : <i><?=$result['1']?></i></div>
        <?php endif; ?>
        
        <div id="logo-content-title"><h1><?=ucfirst($post['Post']['title'])?></h1></div>
        <div id="logo-content-content">
            <?=$html->image('logos/'.$post['Path']['name'].$post['Post']['image'].'_thumb.jpg',array('alt'=>$post['Post']['title'],'url'=>$baseUrl.'/img/logos/'.$post['Path']['name'].$post['Post']['image'].'.jpg'))?>
        </div>
        <div id="logo-content-share">
            <div id="logo-content-navigation">
                <?php if(!empty($prevPost)):?>
                    <strong><span class="prev-slide-image"><?=$html->link('Prev','/view/'.$prevPost['Post']['slug'],array('title'=>$prevPost['Post']['title']))?></span></strong>
                <?php else :?>
                    <strong><span class="prev-slide-image" id="passive"><?=$html->link('Prev','#',array('title'=>'This is first logo'))?></span></strong>
                <?php endif;?>
                <?php if(!empty($nextPost)):?>
                    <strong><span class="prev-slide-image"><?=$html->link('Next','/view/'.$nextPost['Post']['slug'],array('title'=>$nextPost['Post']['title']))?></span></strong>
                <?php else :?>
                    <strong><span class="prev-slide-image"  id="passive"><?=$html->link('Next','#',array('title'=>'This is the last logo'))?></span></strong>
                <?php endif;?>
            </div>
            <div id="logo-content-favorite">
                <div id="logo-content-favorite-box">
                 <h1><?=$html->link('I like it!','#',array('title'=>'If you like this logo desing then click this','id'=>'favorite-like'))?> </h1>
                 </div>
                 <div id="logo-content-favorite-result"></div>
                 <div class="clear"></div>
            </div>
            <div class="clear"></div>
        </div>
        <div id="logo-content-description">
            <div class="logo-content-title"><h1>Description</h1></div>
            <div class="logo-content-description">
                <?=$post['Post']['description']?>
            </div>
        </div>
        <div id="logo-content-comment">
            <div id="logo-content-comment-title"><h1>Comment</h1></div>
            <?php if(!empty($comments)) :?>
                <?php foreach($comments as $comment): ?>
                    <div class="comment-block" id="comment-block-<?=$comment['Comment']['comment_id']?>">
                        <div class="comment-block-image">
                            <img height="50" width="50" src="http://localhost/www.gravatar.com/avatar/<?=md5($comment['Comment']['email'])?>?s=50&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G" alt="<?=$comment['Comment']['name']?>" />
                        </div>
                        <div class="comment-block-description">
                            <?php if(!empty($comment['Comment']['website'])):?>
                                <h1><?=$html->link($comment['Comment']['name'],'#')?> says :</h1>
                            <?php else:?>
                                <h1><?=$comment['Comment']['name']?> says :</h1>
                            <?php endif;?>
                             <?=$comment['Comment']['description']?>
                        </div>
                        <div class="clear"></div>
                    </div>
                <?php endforeach; ?>
            <?php else :?>
                <div class="comment-block">
                    <div class="comment-block-description">
                        <h1>Give first comment</h1>
                    </div>
                    <div class="clear"></div>
                </div>
            <?php endif;?>
        </div>
        <div id="pagination">
            <?php $paginator->options(array('url' => $this->passedArgs,'separate'=>''));?>
            <?php
            echo $paginator->prev('&laquo; Prev ', array('escape' => false,'id'=>'prev'));
            echo '&nbsp';
            echo $paginator->numbers(array('class' => 'selectedm','separator'=>'&nbsp;'));
            echo '&nbsp';
            echo $paginator->next(' Next &raquo;', array('escape' => false,'id'=>'next'));
            ?>
        </div>
        
        <div id="logo-content-response">
            <div id="logo-content-response-title"><h1>Give comment</h1></div>
            <div id="logo-content-response-content">
                <?=$form->create('Comment')?>
                <?=$form->input('Comment.name',array('label'=>'Name','div'=>'text'))?>* required<div class="clear"></div><div id="error-name" class="error"></div>
                <?=$form->input('Comment.email',array('label'=>'Email','div'=>'text'))?> * required & not published<div class="clear"></div><div id="error-email" class="error"></div>
                <?=$form->input('Comment.website',array('label'=>'Website','div'=>'text'))?><div class="clear"></div>
                <div class="text">
                    <label>Comment </label>
                    <?=$form->textarea('Comment.description',array('cols'=>'30','rows'=>'8'))?>
                    <div id="error-description" class="error"></div>
                </div>
                <?=$form->input('Comment.post',array('type'=>'hidden','value'=>$post['Post']['slug']))?>
                <?=$form->submit('Submit comment',array('id'=>'submit-comment','div'=>false)); ?>
                <?=$form->end(); ?>
                <div id="commentError" style="display:none;"></div>
            </div>
        </div>
    </div>

    <div id="logo-sidebar">
        <div class="logo-sidebar-block">
            <div class="logo-sidebar-title"><h1>Logo info</h1></div>
            <div class="logo-sidebar-content">
                <strong>Category :</strong> <?=$post['Category']['name']?><br />
                <?php if(!empty($post['Tag'])):?>
                   <strong>Tags : </strong>
                    <?php foreach($post['Tag'] as $tag) :?>
                           <?=$tag['name'].' '?>
                   <?php endforeach;?>
                   <br />
                <?php endif;?>
                <strong>Created : </strong><?=date("d M Y", strtotime($post['Post']['created']));?><br />
                <strong>Views : </strong><?=$post['Post']['view']?><br />
                <strong>People like it : </strong><?=$post['Post']['rate_count']?><br />
            </div>
        </div>

        <div class="logo-sidebar-block">
            <div class="logo-sidebar-title"><h1>Related logo</h1></div>
            <?php if(!empty($relatedPosts)) :?>
                <?php foreach($relatedPosts as $related):?>
                    <div class="logo-sidebar-content">
                        <div class="logo-sidebar-image">
                                <?=$html->image('thumbs/'.$related['Path']['name'].$related['Post']['image'].'_thumb.jpg',array('alt'=>$related['Post']['title'],'url'=>$baseUrl.'/view/'.$related['Post']['slug']))?>
                        </div>
                        <div class="logo-sidebar-description">
                            <h1><?=$html->link(ucfirst($related['Post']['title']),'/view/'.$related['Post']['slug'])?></h1>
                            <?=date("d M Y", strtotime($related['Post']['created']));?>
                        </div>
                        <div class="clear"></div>
                    </div>
                <?php endforeach; ?>
            <?php else:?>
                <div class="logo-sidebar-content">No related logo</div>
            <?php endif; ?>
        </div>
    </div>
    <div class="clear"></div>

</div>
